# -*- coding: utf-8 -*-
# models
# models
from openerp import fields, models, api

class Customer(models.Model):
    _inherit= 'res.partner'

    country_id=fields.Many2one('res.country', 'Country', ondelete='restrict',default=49)
    is_area=fields.Boolean("Regional agency", default=False)
    area=fields.Char(string="Area")
    partner_type=fields.Selection([('internal',u'本部区域'),('area',u'代理区域'),('sale',u'零售'),('out',u'外贸客户')],string=u"客户类型")
    is_company=fields.Boolean('Is a Company', help="Check if the contact is a company, otherwise it is a person",default=True)
    unit_type=fields.Selection([('investor',u'投资方'),('constructer',u'建设单位'),('designer',u'设计单位'),('builder',u'施工单位')],string=u"单位类型")
    is_unit=fields.Boolean(string=u"合作单位",default=False)
    is_transport=fields.Boolean(string=u"运输公司",default=False)
    is_agent=fields.Boolean(string="代理商",default=False)

    saleman_id=fields.Many2one('res.users',string=u"创建客户的用户",default=lambda self: self.env.user)
    user_manager=fields.Many2one('res.users',string=u"创建客户用户的部门经理",store=True)
    user_manager2=fields.Many2one('res.users',string=u"创建用户的上级部门经理",store=True)

    @api.one
    def _get_manager_name(self):
        return self.user_manager.name

    @api.one
    def _get_manager2_name(self):
        return self.user_manager2.name

    @api.onchange('saleman_id')
    def _onchange_create_uid(self):
        if self.saleman_id and self.saleman_id.employee_ids[0]:
            self.user_manager = self.saleman_id.employee_ids[0].department_id.manager_id.user_id
            if self.saleman_id.employee_ids[0].department_id.parent_id:
                self.user_manager2=self.saleman_id.employee_ids[0].department_id.parent_id.manager_id.user_id
